<?php

abstract class ZFWork_Controller extends Zend_Controller_Action {

	protected $_dirAdminCss = '/temas/work';
	protected $_dirJs;
	protected $_dirAdminJs = '/lib/work';
	protected $_initDefaultCss = true;

	abstract protected function initAdmin();

	abstract protected function initNavigation();

	public function init() {
		if ('login' != Zend_Controller_Front::getInstance()->getRequest()->getControllerName()) {
			$this->checkLogin();
			$this->initNavigation();
		}

		$this->_dirJs = 'http://' . HOST_STATIC . '/lib';

		$this->initDefaultCss();
		$this->initAdmin();
	}

	protected function checkLogin() {
		$auth = Zend_Auth::getInstance();

		if (!$auth->hasIdentity()) {
			$this->_redirect(ZFKiller_View_Helper_Url::urlStatic(
							array('controller' => 'login', 'action' => 'index'), null, true, false
					));
		}

		$this->view->adminUser = Zend_Auth::getInstance()->getIdentity();
	}

	private function initDefaultCss() {
		if ($this->_initDefaultCss) {
			$this->view->headLink()->appendStylesheet('/temas/boxie-admin/a.css', 'screen, projection, tv');
			$this->view->headLink()->appendStylesheet('/temas/boxie-admin/blue.css', 'screen, projection, tv');
			$this->view->headLink()->appendStylesheet('/temas/boxie-admin/a2.css', 'screen, projection, tv');
			$this->view->headLink()->appendStylesheet('/temas/boxie-admin/ie.css', 'screen, projection, tv', 'IE');
		}
	}

	protected function addJQuery($addUi = false) {
		if ($addUi) {
			$this->view->headLink()->prependStylesheet($this->_dirJs . '/jq-ui/css/redmond/jquery-ui-1.8.16.custom.css', 'screen');
			$this->view->headScript()->prependFile($this->_dirJs . '/jq-ui/jq-ui.js');
		}
		$this->view->headScript()->prependFile($this->_dirJs . '/jq.js');
	}

	protected function addJQueryModal($addUi = false) {
		$this->view->headLink()->prependStylesheet($this->_dirJs . '/modal/modal.css', 'screen');
		$this->view->headScript()->prependFile($this->_dirJs . '/jq.modal.js');

		$this->view->headLink()->appendStylesheet('/temas/work/modal.css', 'screen, projection, tv');

		$this->addJQuery($addUi);
	}

	protected function noRender() {
		$this->_helper->layout()->disableLayout();
		$this->_helper->viewRenderer->setNoRender(true);
	}

}